package com.shopping.controller.back;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shopping.commons.response.DataGradResp;
import com.shopping.commons.response.MessageResp;
import com.shopping.model.User;
import com.shopping.param.UserParam;
import com.shopping.service.IUserService;

/**
 * 用户的   Conroller
 * @author Administrator
 *
 */
@Controller
@RequestMapping("back/user") 
public class UserController {

	@Autowired
	private IUserService userService;
	
	/**
	 * 增加某个用户
	 * @param request
	 * @param param
	 * @return
	 */
	@RequestMapping("insert")
	@ResponseBody  ///这个是吧MessageResp转成  json 的注解   普遍就是   对应  ajax 的请求    
	public MessageResp insert(HttpServletRequest request,User param){

		return userService.insert(param);
	}
	
	/**
	 * 查询 用户
	 * @param request
	 * @param param
	 * @return    两个参数  必须分开  /
	 */
	@RequestMapping("select/{delflag}")//resetful风格的，这样只要拼接一下就可以
	@ResponseBody  
	public DataGradResp<User> select(HttpServletRequest request,UserParam param,@PathVariable("delflag")String delflag){
		//这里调用的就是  IUserService里面定义的 select方法了，   是靠  参数来判断的， ICommonService里面用的是User
		param.setDelflag(delflag);
		return userService.select(param);
	}
	
	/**
	 * 单个 删除用户   
	 * @param request
	 * @param param
	 * @return
	 */
	/*resetful 接口规范  接口编码的风格*/
	@RequestMapping(value="{id}",method=RequestMethod.DELETE)
	@ResponseBody 
	public MessageResp delete(HttpServletRequest request,@PathVariable("id") Integer id){
		return userService.delete(id);
	}
	
	/**
	 * 多个 删除用户   
	 * @param request
	 * @param param
	 * @return
	 */
	/*resetful 接口规范  接口编码的风格*/
	@RequestMapping(value="del/{ids}",method=RequestMethod.DELETE)
	@ResponseBody 
	public MessageResp batchDelete(HttpServletRequest request,@PathVariable("ids") String ids){
		return userService.batchDelete(ids);
	}
	 /*
	 * 修改用户
	 * @param request
	 * @param param
	 * @return
	 **/
	@RequestMapping("update")
	@ResponseBody 
	public MessageResp update(HttpServletRequest request,User param){
		return userService.update(param);
	}

}
